import java.util.Locale;

public class Test {
//    public static void main(String[] args) {
//        System.out.println(firstUniqChar());
//    }
//    public static int firstUniqChar() {
//        String s = "aabccde";
//        int[] count = new int[26];
//        for(int i = 0; i < s.length(); i++) {
//            char ch = s.charAt(i);
//            count[ch-'a']++;
//        }
//        for (int i = 0; i < s.length(); i++) {
//            char ch = s.charAt(i);
//            if (count[ch-'a'] == 1) {
//                return i;
//            }
//        }
//        return -1;
//    }
public static void main(String[] args) {
    Solution s = new Solution();
    System.out.println(s.isPalindrome2("A man, a plan, a canal: Panama"));
}
}
class Solution {
    public boolean isPalindrome1(String s) {
        s = s.toLowerCase().replaceAll("[^a-zA-Z0-9]","");
        StringBuilder str = new StringBuilder(s);
        str.reverse();
        if (str.toString().equals(s)) {
            return true;
        }
        return false;
    }
    public boolean isPalindrome2(String s) {
        s = s.toLowerCase().replaceAll("[^a-zA-Z0-9]","");
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            if (s.charAt(left) != s.charAt(right)) {
                return false;
            } else {
                left++;
                right--;
            }
        }
        return true;
    }
}
